Fibonanchi numbers


In [1]:
a=[1,1]

def get(arr,i):
#     return arr[i] if i < len(arr) else None
    return (arr[i:i+1]+[None])[0]

def f0(n):
    return 1 if n<2 else f0(n-2)+f0(n-1)

def f(n):
    if  get(a,n) is None: 
        a[n:n+1] = [f(n-2) + f(n-1)]
    return a[n]

def f2(n):
    if n >= len(a):
        a.append(f(n-2) + f(n-1))
    return a[n]

    


f2(50)


Out[1]:
20365011074

In [2]:
%%javascript

let a = []
a[0]=a[1]=1;


function f(n){
    if (!a[n]) 
        a[n]= f(n-2) +f(n-1);
    return (a[n]);
}

f(100)
element.html(a.toString().replace(/,/g,', '));



In [ ]: